<?php
declare (strict_types=1);

namespace app\circle\service\admin;

use app\circle\logic\admin\Circle as CircleLogic;
use app\circle\logic\admin\Comment as CircleCommentLogic;
use app\common\service\BaseService;
use think\annotation\Inject;
use think\facade\Request;

/**
 * Class Circle
 *
 * @package app\circle\service\admin
 */
class Circle extends BaseService
{

    /**
     * @Inject()
     *
     * @var CircleLogic
     */
    protected $circleLogic;

    /**
     * @Inject()
     *
     * @var CircleCommentLogic
     */
    protected $circleCommentLogic;

    /**
     * 朋友圈列表
     * Author: Martinsun <syh@sunyonghong.com>
     * Date: 2021/9/15
     *
     * @return \think\Response
     * @throws \think\db\exception\DbException
     */
    public function getList()
    {
        $data = $this->circleLogic->getList();

        return $this->parseToData($data, 1, '获取成功');
    }

    /**
     * 单个删除
     * Author: Martinsun <syh@sunyonghong.com>
     * Date: 2020/12/21
     *
     * @param int $id
     * @return \think\Response
     */
    public function delete(int $id)
    {
        $this->circleLogic->deleteCircles($id);

        return $this->parseToData([], 1, '删除成功');
    }

    /**
     * 批量删除
     * Author: Martinsun <syh@sunyonghong.com>
     * Date: 2020/12/21
     *
     * @param string $ids
     * @return \think\Response
     */
    public function deletes(string $ids)
    {
        $this->circleLogic->deleteCircles($ids);

        return $this->parseToData([], 1, '删除成功');
    }

    /**
     * setRecommend
     * Author: Martinsun <syh@sunyonghong.com>
     * Date: 2021/9/15
     *
     * @param int $id
     * @return \think\Response
     */
    public function recommend(int $id)
    {
        $isRecommend = Request::put('recommend/d');

        $this->circleLogic->setRecommend($id, $isRecommend);

        return $this->parseToData([], 1, '操作成功');
    }

    /**
     * 获取圈子的详情
     * Author: Martinsun <syh@sunyonghong.com>
     * Date: 2021/9/16
     *
     * @param int $id
     * @return \think\Response
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function detail(int $id)
    {
        // 基本信息
        $info     = $this->circleLogic->getInfoById($id);
        $comments = $this->circleCommentLogic->getCommentsByCircleId($id);

        return $this->parseToData([
            'info'     => $info,
            'comments' => $comments
        ], 1);
    }

}